class RecordItem extends ComponentEx {

    private lab_rank: eui.Label;
    private lab_roomid: eui.Label;
    private lab_card: eui.Label;
    private item_1: RecordPlayerItem;
    private item_2: RecordPlayerItem;
    private item_3: RecordPlayerItem;
    private item_4: RecordPlayerItem;
    private btn_details: ButtonEx;
    private lab_time: eui.Label;

    public constructor() {
        super();
        this.skinName = "RecordItemSkin";
    }

    childrenCreated() {
        super.childrenCreated();

        this.btn_details.addEventListener(egret.TouchEvent.TOUCH_TAP, this.clickHandler, this);
    }

    private clickHandler(e: egret.TouchEvent): void {
        switch (e.currentTarget) {
            case this.btn_details:
                game.roomid = this.data.roomid;
                game.recordInfos = this.data.persons;
                game.isReplaying = true;

                Replayer.shareIF.item_id = this.data.item_id.split("#")[1];

                gameManager.socketManager.send(20, { id: this.data.id });

                let panel: RecordPanel = gameManager.find('RecordPanel');
                if (panel) {
                    panel.updateDetailsInfo(this.data.rank, this.data.roomid, this.timeStr)
                }

                gameManager.i.dispatchEvent(GameEventType.UPDATE_RECORD_DETAILS_TYPE, this.data.zhanji_type);
                break;
        }
    }

    update(data): void {
        if (!data) return;

        this.data = data;

        switch (this.data.zhanji_type) {
            case 1:
                this.skinState = 'daikai';
                break;
            case 2:
                this.skinState = 'circle';
                break;
            case 3:
                this.skinState = 'normal';
                break;
        }

        this.lab_rank.text = "" + this.data.rank;
        this.lab_roomid.text = "" + this.data.roomid;


        switch (this.data.cost_card[0]) {
            case 1:
                this.lab_card.text = this.data.cost_card[1] + '张/人';
                break;
            case 2:
                this.lab_card.text = this.data.cost_card[1] + '张';
                break;
        }

        let person: any;
        let item: RecordPlayerItem;
        for (let i = 1; i <= 4; i++) {
            item = this['item_' + i];

            person = this.data.persons[i - 1];
            if (person) {
                item.update(person);
                item.score = +this.data.total[+person.pos - 1];
            }
            else {
                item.clean();
            }
        }

        this.lab_time.text = this.timeStr;
    }

    private get timeStr() {
        return StringUtils.getYTDByTimestamp(this.data.time * 1000) + " " + StringUtils.getHMSByTimestamp(this.data.time * 1000);
    }
}